<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 类:把相同的属性和方法,提取成一个模板,就叫做类,是抽象的
        // 对象是类的实例,是具体的
        class Person{
            // constructor用于初始化属性,如果没有属性,可以不写
            constructor(name,age){
                this.name=name;
                this.age=age;
            }
            run(){
                console.log(`我${this.name}爱跑步`);
            }
            eat(){
                console.log(`我${this.name}爱喝奶茶`);
            }
            sleep(){
                console.log(`我${this.name}爱睡觉`);
            }
        }
        var p1=new Person("刘德华",20);
        p1.run();
        var p2=new Person("周杰伦",20);
        p2.eat();
    </script>
</body>
</html>